package com.kaifamiao.jsptags;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;

@WebServlet("/prepare")
public class PrepareServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        String[] array = {"李逵", "宋江", "吴用", "王婆"};
        request.setAttribute( "names", array );

        request.setAttribute( "set", Set.of("孙悟空","孙行者","行者孙","者行孙"));

        request.setAttribute( "list", List.of("诸葛亮","周瑜","孙权","徐庶"));

        request.setAttribute( "map", Map.of("小乔","周瑜","孙尚香","刘备"));

        String path = "/tags/iterate.jsp";
        RequestDispatcher dispatcher = request.getRequestDispatcher( path );
        dispatcher.forward(request,response);
    }

}
